<script setup>
import { getHotGoodsAPI } from '@/apis/detail';
import { computed, onMounted, ref } from 'vue';
import { useRoute } from 'vue-router';

const route = useRoute();

const props = defineProps({
  hotType: {
    type: Number
  }
});

const TYPE_MAP = {
  1: '24小时热榜',
  2: '周热榜'
};
const title = computed(() => TYPE_MAP[props.hotType]);

const hotList = ref([]);
const getHotList = async () => hotList.value = (await getHotGoodsAPI({
  id: route.params.id,
  type: props.hotType,
})).result;

onMounted(() => getHotList());
</script>

<template>
  <div class="goods-hot">
    <h3>{{ title }}</h3>
    <!-- 商品区块 -->
    <RouterLink to="/" class="goods-item" v-for="hotItem in hotList" :key="hotItem.id">
      <img :src="hotItem.picture" alt="" />
      <p class="name ellipsis">{{ hotItem.name }}</p>
      <p class="desc ellipsis">{{ hotItem.desc }}</p>
      <p class="price">&yen;{{ hotItem.price }}</p>
    </RouterLink>
  </div>
</template>

<style scoped lang="scss">
.goods-hot {
  h3 {
    height: 70px;
    background: $helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }

  .goods-item {
    display: block;
    padding: 20px 30px;
    text-align: center;
    background: #fff;
    width: 280px;

    img {
      width: 160px;
      height: 160px;
    }

    p {
      padding-top: 10px;
    }

    .name {
      font-size: 16px;
    }

    .desc {
      color: #999;
      height: 29px;
    }

    .price {
      color: $priceColor;
      font-size: 20px;
    }
  }
}
</style>